import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import Routers from './router.js'
import BackTop from './components/BackTop';
import net from './libs/http';
import api from './libs/api';
Vue.prototype.$ajax = net;
Vue.prototype.$api = api;

import './assets/less/base.less';
import './assets/iconfont/iconfont.css';
import './libs/appback.js';
import './libs/vshow.js';
import './vant-ui'

import VueTouch from 'vue-touch';

VueTouch.config.swipe = {
    threshold: 200,
    direction: 'horizontal'
}
Vue.use(VueTouch,{name:'v-touch'});

Vue.component("BackTop",BackTop);
Vue.use(VueRouter);

Vue.prototype.$back = function(){
  history.back();
}

// The routing configuration
const RouterConfig = {
  // mode:"history",
  scrollBehavior(to,from,savedPosition){
      return { x: 0, y: to.meta.savedPosition || 0 }    
  },
  routes: Routers
};
const router = new VueRouter(RouterConfig);
router.beforeEach((to, from , next) => { 
  if (from.meta.keepAlive) {
      //记录离开的滚动位置  
      from.meta.savedPosition = document.body.scrollTop || document.documentElement.scrollTop;
  }
  next();
});
router.afterEach((to,from) => {  
})

Vue.config.productionTip = false;

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')